<?php
declare(strict_types=1);

namespace app\common\business;

use app\common\lib\ClassArr;
use app\common\lib\Num;
use app\common\lib\sms\AliSms;

class Sms extends BusBase
{
    /**
     * 发送验证码短信
     * @param  string  $phoneNumber
     * @param  int  $len
     * @param  string  $type
     * @return bool
     * @throws \ReflectionException
     */
    public function sendCode(string $phoneNumber, int $len, $type = "ali"): bool
    {
        $code =  Num::getCode($len);
        $class = ClassArr::smsClassStat();
        $classObj = ClassArr::initClass($type,$class);
        $sms = $classObj::sendCode($phoneNumber,$code);
        if(!$sms){
            return false;
        }
        cache(config('redis.code_pre').$phoneNumber,$code,config('redis.code_expire'));
        return true;
    }
}